﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.ViewModal;

namespace CubicFWNet.Data.SystemManager
{
    public class FinanceCostRepository : RepositoryBase<FinanceCost>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="status">订单状态</param>
        /// <param name="fcStatus">财务审核状态</param>
        /// <param name="productName">客户名称</param>
        /// <param name="number">订单编号</param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public IQueryable<ProductTechnologyView> GetList(int status, int fcStatus, string productName, string number, DateTime beginTime, DateTime endTime)
        {
            var result = from fc in dbcontext.FinanceCosts
                         join orders in dbcontext.Orders
                         on fc.OrderId equals orders.Id
                         join op in dbcontext.OrderProducts
                         on fc.OrderProductId equals op.Id
                         join pro in dbcontext.Products
                         on op.ProductId equals pro.Id
                         //join cs in dbcontext.Customers
                         // on orders.CustomeId equals cs.Id
                         where //(status == -10 || orders.Status == status)
                               pro.Name.Contains(productName)
                               && op.Status != -1
                               && beginTime <= orders.CreateTime
                               && endTime >= orders.CreateTime
                               && (fc.Status == fcStatus)
                         //&& (customeName == "" || cs.Name.Contains(customeName))
                         select new ProductTechnologyView
                         {
                             //OrderNum = orders.Number,
                             //OrderCustomeName = cs.Name,
                             CreateTime = orders.CreateTime,
                             OrderStatus = orders.Status,
                             Status = fc.Status,
                             OrderFinalPrice = fc.PriceConfirm,
                             OrderId = orders.Id,
                             OrderProductId = fc.OrderProductId,
                             FinanceCostId = fc.Id,
                             ApplyTime = fc.ApplyTime,
                             FinanceCostsStatus = fc.Status,
                             ProductName = pro.Name
                         };
            return result;
        }
    }
}
